function FaceTarget()
{
	if ${Target(exists)}
	{
		;EA "Facing" "${Target.Name}"
		call Face ${Target.X} ${Target.Z}
	}
}
function MoveToTarget(float Distance)
{
	declare TargetGUID string local
	declare stuck uint local 0
	MadePosition:Set[FALSE]
	if ${Target(exists)}
	{
		TargetGUID:Set[${Target.ID}]
		call FaceTarget
		if ${Actor[${TargetGUID}](exists)} && ${Math.Distance[${Me.X},${Me.Z},${Target.X},${Target.Z}]} > ${Distance}
		{
			EA "Moving Toward" "${Target.Name}"
			call FaceTarget
			press "${MOVEFORWARD}"
			while ${Actor[${TargetGUID}](exists)} && ${Math.Distance[${Me.X},${Me.Z},${Me.Y},${Target.X},${Target.Z},${Target.Y}]} > ${Distance} && ${stuck} <= 5
			{
				;call CheckMovingAggro
				call FaceTarget

				if !${Target(exists)}
				{
					Target "${TargetGUID}"
				}

				if ${Me.WaterDepth} > 0 && ${Actor[${Target.ID}].IsSwimming}
				{
					if ${Math.Distance[${Me.Y},${Target.Y}]} > 0.5
					{
						EA "Water Depth" "Difference Detected"
						while ${Math.Distance[${Me.Y},${Target.Y}]} > 0.5
						{
							call FaceTarget
							if ${Target.Y} < ${Me.Y}
							{
								press -hold "${SWIMDOWN}"
							}
							elseif ${Target.Y} > ${Me.Y}
							{
								press -hold "${SWIMUP}"
							}
						}
						press -release "${SWIMDOWN}"
						press -release "${SWIMUP}"
					}
				}

				wait 1
				if ${Math.Distance[${Me.X}, ${Me.Z}, ${Target.X}, ${Target.Z}]} > 20
				{
					call RandomShuffle
				}
				MoveX:Set[${Me.X}]
				MoveZ:Set[${Me.Z}]
				MoveY:Set[${Me.Y}]
				wait 1

				call CheckObstacle ${Target.X} ${Target.Z} ${Target.Y}
				if ${Return}
				{
					stuck:Inc
					wait ${Math.Rand[1]:Inc[5]}
					call FaceTarget
					call Obstacle
				}
			}
			call StopMoving
			call FaceTarget
			if ${Math.Distance[${Me.X}, ${Me.Z}, ${Target.X}, ${Target.Z}]} <= ${Distance}
			{
				MadePosition:Set[TRUE]
			}
			EA "Stopping @ ${Distance}" "${Target.Name}"
		}
	}
}
function MoveFromTarget(float Distance)
{
	declare TargetGUID string local
	declare stuck uint local 0
	MadePosition:Set[FALSE]
	if ${Target(exists)}
	{
		TargetGUID:Set[${Target.ID}]
		call FaceTarget
		if ${Actor[${TargetGUID}](exists)} && ${Math.Distance[${Me.X},${Me.Z},${Target.X},${Target.Z}]} < ${Distance}
		{
			EA "Moving Toward" "${Target.Name}"
			call FaceTarget
			press -hold ${MOVEBACKWARD}
			while ${Actor[${TargetGUID}](exists)} && ${Math.Distance[${Me.X},${Me.Z},${Target.X},${Target.Z}]} < ${Distance} && ${stuck} <= 5
			{
				;call CheckMovingAggro
				call FaceTarget
				if !${Target(exists)}
				{
					Target "${TargetGUID}"
				}
				wait 1
				if ${Math.Distance[${Me.X}, ${Me.Z}, ${Target.X}, ${Target.Z}]} > 20
				{
					call RandomShuffle
				}
				MoveX:Set[${Me.X}]
				MoveZ:Set[${Me.Z}]
				wait 1

				call CheckObstacle ${Target.X} ${Target.Z}
				if ${Return}
				{
					stuck:Inc
					wait ${Math.Rand[1]:Inc[5]}
					call FaceTarget
					call Obstacle
				}
			}
			call StopMoving
			call FaceTarget
			if ${Math.Distance[${Me.X}, ${Me.Z}, ${Target.X}, ${Target.Z}]} <= ${Distance}
			{
				MadePosition:Set[TRUE]
			}
			EA "Stopping @ ${Distance}" "${Target.Name}"
		}
	}
}
function MoveToTargetRanged()
{
	call MoveToTarget 25.000000
}
function MoveToTargetMidRanged()
{
	call MoveToTarget 20.000000
}
function MoveToTargetMelee()
{
	call MoveToTarget 5.000000
}
function MoveFromTargetRanged()
{
	call MoveFromTarget 25.000000
}
function MoveFromTargetMidRanged()
{
	call MoveFromTarget 20.000000
}
function MoveFromTargetMelee()
{
	call MoveFromTarget 5.000000
}
